//
//  PHomeFilterAreaView.m
//  Btpin
//
//  Created by Vic on 2019/12/15.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PHomeFilterAreaView.h"
#import "LYSelectCityView.h"

@interface PHomeFilterAreaView ()
{
    
}
@property (nonatomic, strong) LYSelectCityView *cityView;
@end

@implementation PHomeFilterAreaView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"city" withExtension:@"plist"];
    NSArray *cityArray = [NSArray arrayWithContentsOfURL:URL];
    
    self.cityView = [[LYSelectCityView alloc] initCityData:cityArray CityState:CityStateThird];
    [self addSubview:self.cityView];
    
    UIView *bgView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(self.cityView), WIDTH, 70) backgroundColor:COLOR_OF_WHITE];
    [self addSubview:bgView];
    [bgView borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeTop];
    
    UIButton *cancelBtn = [UIToolsControl initButtonWithFrame:CGRectMake(LeftSpace, 15, ScalePS(120), 40) imageName:nil target:self action:@selector(cancelBtnTap) title:@"取消" titleColor:THEMECOLOR_OF_TEXT_666666];
    cancelBtn.backgroundColor = COLOR_OF_CLEAR;
    cancelBtn.titleLabel.font = Font(Font_17);
    cancelBtn.layer.cornerRadius = 20;
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.layer.borderColor = THEMECOLOR_OF_Line_Color.CGColor;
    cancelBtn.layer.borderWidth = lineH;
    [bgView addSubview:cancelBtn];
    
    UIButton *okBtn = [UIToolsControl initButtonWithFrame:CGRectMake(EndX(cancelBtn)+ScalePS(10), 15, WIDTH-ScalePS(160), 40) imageName:nil target:self action:@selector(okBtnTap) title:@"确定" titleColor:COLOR_OF_WHITE];
    okBtn.backgroundColor = THEMECOLOR_OF_ORANGE;
    okBtn.titleLabel.font = Font(Font_17);
    okBtn.layer.cornerRadius = 20;
    okBtn.layer.masksToBounds = YES;
    [bgView addSubview:okBtn];
}
- (void)okBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pHomeFilterAreaViewOKInfo:)]) {
        NSDictionary *dic = [self.cityView getAllCityInfo];
        [self.delegate pHomeFilterAreaViewOKInfo:dic];
    }
}
- (void)cancelBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pHomeFilterAreaViewCancel)]) {
        [self.delegate pHomeFilterAreaViewCancel];
    }
}

@end
